<?php
/**
 * ============================================================================
 * Copyright (c) 2015-2018 贵州大师兄信息技术有限公司 All rights reserved.
 * siteַ: http://www.dsxcms.com
 * ============================================================================
 * @author:     David Song<songdewei@163.com>
 * @version:    v1.0.0
 * ---------------------------------------------
 * Date: 2018/9/11
 * Time: 下午12:11
 */

namespace App\Library;


use Illuminate\Support\Facades\Validator;

class CustomValidator
{
    public static function register()
    {
        //手机号
        Validator::extend('mobile', function ($attribute, $value, $parameters, $validator) {
            return preg_match('/^1[3|4|5|7|8]\d{9}$/', $value);
        });
        //邮箱或手机号
        Validator::extend('account', function ($attribute, $value, $parameters, $validator) {
            if (preg_match('/^1[3|4|5|7|8]\d{9}$/', $value))
            {
                return true;
            }

            if (filter_var($value, FILTER_VALIDATE_EMAIL)){
                return true;
            }
            return false;
        });

        //密码
        Validator::extend('password', function ($attribute, $value, $parameters, $validator) {
            if (strlen($value) > 5 && strlen($value) < 21) {
                return true;
            }
            return false;
        });
    }
}
